﻿var zombies = zombies || {};

zombies.publayout = function () {
    var self = this;
    //channel info
    self.ChannelName = ko.observable();
    self.ChannelCover = ko.observable();
    self.About = ko.observable();
    self.PubId = ko.observable();
    self.Address = ko.observable();
    self.Facebook = ko.observable();
    self.LogoLink = ko.observable();
    self.Phone = ko.observable();

    self.Cover = ko.computed(function () {
        return "url(../" + self.ChannelCover() + ") no-repeat fixed center top / cover transparent";
    });
}

zombies.rightBar = function () {
    var self = this;
    self.Subcribers = ko.observableArray();
    self.Comments = ko.observableArray();
};

var loadchannel = function (pubid) {
    $.ajax({
        type: "GET",
        url: "/api/Publisher/GetPubChannel/" + pubid,
        contentType: "application/json",
        dataType: 'json'
    }).done(function (item) {
        layoutModel.PubId(item.PubId);
        layoutModel.ChannelName(item.ChannelName);
        if (item.ChannelCover === null) layoutModel.ChannelCover('../Advertise/DefaultAssets/intro.jpg');
        else layoutModel.ChannelCover(item.ChannelCover);
        layoutModel.About(item.About);
        layoutModel.Address(item.Address);
        layoutModel.LogoLink(item.LogoLink === null ? '../Advertise/DefaultAssets/1.jpg' : item.LogoLink);
        layoutModel.Facebook(item.Facebook);
        layoutModel.Phone(item.Phone);
    }).fail(function () {
        toastr.error('Lỗi :(');
    });
};

//get params
var pubId = document.URL.split('/').pop();
if (!pubId) {
    window.location.replace('http://' + window.location.host + '/home/index');
}
//model
var layoutModel;
var rightBar;
$(document).ready(function () {
    layoutModel = new zombies.publayout();
    //rightBar = new zombies.rightBar();
    loadchannel(pubId);

    ko.applyBindings(layoutModel, document.getElementById("cover_publisher"));
    //ko.applyBindings(rightBar, document.getElementById("right_publisher"));
});